# 假设这是原始数据
ANIMALS = ["鼠", "牛", "虎", "兔", "龙", "蛇"]  # 示例动物列表
YAO_WEI = ["初", "二", "三", "四", "五", "上"]  # 爻位
gua_dict = {'six_mode': 5}  # 示例值，实际使用时需要设置


# 原始映射生成函数
def generate_mapping():
    mapping = {}
    for line in range(6):
        key = ANIMALS[(gua_dict['six_mode'] + 10 - line) % 6]
        value = YAO_WEI[line] + '爻'
        mapping[key] = value
    return mapping


# 反向查找函数
def find_value_by_animal(animal, mapping):
    animal_index = ANIMALS.index(animal)
    line = (gua_dict['six_mode'] + 10 - animal_index) % 6
    return YAO_WEI[line] + '爻'


# 测试代码
def test_mapping():
    # 生成映射
    mapping = generate_mapping()
    print("生成的映射关系:", mapping)

    # 测试每个动物是否能正确反向查找
    for animal in ANIMALS:
        calculated_value = find_value_by_animal(animal, mapping)
        mapped_value = mapping[animal]

        print(f"\n测试动物: {animal}")
        print(f"映射中的值: {mapped_value}")
        print(f"计算得到的值: {calculated_value}")

        assert calculated_value == mapped_value, f"测试失败: {animal} 的值不匹配"
        print("测试通过!")

    print("\n所有测试通过!")


# 运行测试
test_mapping()